Software Development
Pointers and References in C++
Pointers and References in C++: Allocating Memory with New & Delete Operators
Pointers and References in C++: Getting Started with Pointers
Pointers and References in C++: Using Smart Pointers in Modern C++
Pointers and References in C++: Working with References

Pointers and References in C++: Allocating Memory with New & Delete Operators

Course Number:
it_cpprefdj_02_enus
Lesson Objectives

Pointers and References in C++: Allocating Memory with New & Delete Operators

  • discover the key concepts covered in this course
  • explore pointers and stack and free store memory
  • contrast malloc() and new
  • use the new keyword to allocate memory on the heap
  • use the new and delete keywords on pointers
  • allocate memory for strings and vectors
  • allocate memory for arrays using array new and delete
  • invoke constructors and destructors on arrays
  • contrast const pointers and pointers to consts
  • create constant variables and pointers on those variables
  • create constant pointers on constant and non-constant variables
  • create constant pointers and constant pointers to constants
  • summarize the key concepts covered in this course

Overview/Description
C++, like C, has powerful support for memory allocation and deallocation. In the world of C, these operations are performed using malloc() and free(), which are not to be used in the C++ world. In classic C++, memory allocation and deallocation are performed using the new and delete operators. You will begin this course by understanding the new and delete keywords, and note how these lead to the invocation of the underlying constructors and destructors on whatever objects are being worked with. In contrast, the C versions, that is, malloc() and free(), do not invoke constructors or destructors. You will then move on to the use of array new and array delete, which is how the new and delete followed by square brackets are referred to. Finally, you will look at the differences between const pointers and pointers to consts.

Target

Prerequisites: none

Pointers and References in C++: Getting Started with Pointers

Course Number:
it_cpprefdj_01_enus
Lesson Objectives

Pointers and References in C++: Getting Started with Pointers

  • discover the key concepts covered in this course
  • outline the use of pointers in C++
  • contrast NULL and nullptr
  • create C-style pointers
  • store strings in character arrays and pointers
  • use the nullptr keyword
  • create pointers on string objects
  • use pointers with vectors and maps
  • summarize the key concepts covered in this course

Overview/Description
As a superset of C, C++ also has support for pointer variable types that point to specific memory locations. While the pointer types function similarly, the terms related to pointer variables have evolved from C to C++ and modern C++, as you will see in this course. Begin this course by creating pointers to values and arrays. You will then move to the use of the nullptr keyword, and see how it differs from the NULL value used in C. Finally, you will create pointers to vectors and maps. After completion of this course, you'll have a solid foundation of using pointers to stack memory locations in C++ and create pointers to vectors and maps.

Target

Prerequisites: none

Pointers and References in C++: Using Smart Pointers in Modern C++

Course Number:
it_cpprefdj_03_enus
Lesson Objectives

Pointers and References in C++: Using Smart Pointers in Modern C++

  • discover the key concepts covered in this course
  • outline the concept of smart pointers
  • recall how unique pointers, shared pointers, and strong pointers work
  • create unique pointers to automatically deallocate memory
  • copy, transfer, and reset pointers
  • create shared pointers using various syntaxes
  • examine strong and weak counts of shared pointers
  • examine values stored in shared pointers
  • introduce weak pointers and contrast them with strong pointers
  • recognize the limitations of weak pointers
  • recognize how weak pointers can become invalid
  • recognize how weak pointers can be deallocated
  • summarize the key concepts covered in this course

Overview/Description
Dynamic memory allocation and deallocation in C are performed using malloc() and free(). In classic C++, dynamic memory allocation and deallocation are performed using new and delete, and array new and array delete. In modern C++, it’s smart pointers that take over. Begin this course by examining the idea behind smart pointers. You will then explore the different types of smart pointers, including unique pointers, shared pointers, and weak pointers. Discover why weak pointers are required in some cases to avoid circular references that can cause memory leaks. After completing this course, you'll be able to use smart pointer objects, leverage RAII to use shared, unique, and weak pointers, and avoid circular references using weak pointers.

Target

Prerequisites: none

Pointers and References in C++: Working with References

Course Number:
it_cpprefdj_04_enus
Lesson Objectives

Pointers and References in C++: Working with References

  • discover the key concepts covered in this course
  • contrast references with pointers
  • create references and modify the variables being referred to
  • create references on different types and objects
  • create references and modify variables through them
  • create and use const references
  • use the const_cast operator
  • summarize the key concepts covered in this course

Overview/Description
C++ supports a variable type known as the reference. You can think of references as being easier-to-use, lighter-weight versions of pointers. Begin by getting familiar with the syntax and semantics of references in C++, including the use of the & symbol to denote a reference type. Note some important differences between references and pointers, how references need to be assigned when they are created, how they cannot be reassigned or set to NULL, and how multiple references to the same underlying value are all effectively aliases for that value. Move on to declaring and using variables of reference type. Finally, learn about const references and experiment with different configurations of loops, where the loop variables are references, value types, and const references. Upon course completion, you'll be able to define and initialize variables of reference types, contrast pointers and references, and correctly use const references.

Target

Prerequisites: none

Close Chat Live